package com.svnservices.hannibal.dao;

import com.svnservices.domaininterface.SvnAuthorization;
import com.svnservices.hannibal.activerecord.SvnAuthorizationAR;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import hannibal.dao.db.spring.Dao;

import java.sql.ResultSet;
import java.sql.SQLException;

@javax.annotation.Generated
(
	value="hannibal.generator.Generator",
	comments="",
	date = ""
)
   
public class SvnAuthorizationDao
	extends Dao
{
	protected SvnAuthorizationDao(javax.sql.DataSource _dataSource)
	{
		super(_dataSource);
	}

	protected ParameterizedRowMapper<SvnAuthorizationAR> mapper = new ParameterizedRowMapper<SvnAuthorizationAR>()
	{
		public SvnAuthorizationAR mapRow(ResultSet _resultSet, int _rowNum)
				throws SQLException
		{
			SvnAuthorizationAR svnAuthorization = new SvnAuthorizationAR();

			svnAuthorization.setId(hannibal.util.DatabaseUtil.getString(_resultSet, "id"));
			svnAuthorization.setUser(hannibal.util.DatabaseUtil.getString(_resultSet, "user"));
			svnAuthorization.setPermission(hannibal.util.DatabaseUtil.getString(_resultSet, "permission"));
			svnAuthorization.setRepositoryName(hannibal.util.DatabaseUtil.getString(_resultSet, "repositoryName"));
			
			return svnAuthorization;
		}
	};

	public java.util.Collection<SvnAuthorizationAR> collect(int _offset, int _limit, String _orderBy)
	{
		String sql = "SELECT id AS id, user AS user, permission AS permission, repositoryName AS repositoryName FROM SvnAuthorization ORDER BY :orderBy LIMIT ? OFFSET ?";
		sql = sql.replaceAll(":orderBy", _orderBy);

		return query(sql, this.mapper, _limit, _offset);
	}

	public int insert(SvnAuthorizationAR _svnAuthorization)
	{
		final String sql = "INSERT INTO SvnAuthorization ( id, user, permission, repositoryName) VALUES ( ?, ?, ?, ?)";
		
		return update(sql, _svnAuthorization.getId(), _svnAuthorization.getUser(), _svnAuthorization.getPermission(), _svnAuthorization.getRepositoryName());
	}


	public SvnAuthorization get(final java.lang.String _id)
	{
		final String sql = "SELECT id AS id, user AS user, permission AS permission, repositoryName AS repositoryName FROM SvnAuthorization WHERE id = ?";

		return queryForObject(sql, this.mapper, _id);
	}

	public SvnAuthorization get(SvnAuthorizationAR _svnAuthorization)
	{
		return get(_svnAuthorization.getId());
	}

	public int update(SvnAuthorizationAR _svnAuthorization)
	{
		final String sql = "UPDATE SvnAuthorization SET user = ?, permission = ?, repositoryName = ? WHERE id = ?";

		return update(sql, _svnAuthorization.getUser(), _svnAuthorization.getPermission(), _svnAuthorization.getRepositoryName(), _svnAuthorization.getId() );
	}

	public int del(final java.lang.String _id)
	{
		return delete(_id);
	}

	public int delete(final java.lang.String _id)
	{
		final String sql = "DELETE FROM SvnAuthorization WHERE id = ?";

		return update(sql, _id);
	}

	public int del(SvnAuthorizationAR _svnAuthorization)
	{
		return delete(_svnAuthorization);
	}

	public int delete(SvnAuthorizationAR _svnAuthorization)
	{
		return delete(_svnAuthorization.getId());
	}


}